﻿using DevExpress.Web.ASPxTreeView;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI;
using EntryExit.Utils;

namespace EntryExit
{
    public partial class Analytics : BasePage
    {
        public Employee SelectedEmployee { get; set; }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (this.Master is MainMaster)
            {
                ((MainMaster)this.Master).MasterTreeViewNodeSelected += Analytics_MasterTreeViewNodeSelected;
                
            }
        }

        void Analytics_MasterTreeViewNodeSelected(object source, TreeViewNodeEventArgs e)
        {
            SelectedEmployee = EmployeeManagerContext.GetEmployee(SelectedEmployeeLPN);
            statusWheelPanel.HeaderText = "Analytics : " + SelectedEmployee.EmployeeName;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SqlDataSourceForDoughNut.ConnectionString = EntryExit.ConfigMgr.Instance.GetValue(EntryExit.ConfigKeys.CNFG_HRMS_CONNECTION);
                SqlDataSourceForDoughNut.SelectCommand = DBConstants.CMD_AMS_GET_LEAVE_DISTRIBUTION_FOR_MONTH;

                if (!IsPostBack)
                {
                    SelectedEmployee = EmployeeManagerContext.GetEmployee(SelectedEmployeeLPN);
                    statusWheelPanel.HeaderText = "Analytics : " + SelectedEmployee.EmployeeName;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Page : Analytics.aspx.cs, Event : Page_Load", ex);
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('An internal error occured. Reload the tool and try again. If issue still persists, please report to your administrator..!');", true);
            }
        }
    }
}